package com.yanyuhao.controller;

import com.github.pagehelper.PageInfo;
import com.yanyuhao.common.Result;
import com.yanyuhao.entity.Admin;
import com.yanyuhao.service.AdminService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/admin")
public class AdminController {

    //连接Service
    @Resource
    AdminService adminService;

    @GetMapping("/selectAll")
    public Result selectAll(){
        List<Admin> adminList = adminService.selectAll();
        return Result.success(adminList);
    }

    //分页查询
    //pageNum:当前的页码
    //pageSize:每页的个数
    @GetMapping("/selectPage")
    //**@RequestParam**：自动将 URL 参数绑定到方法参数
    public Result selectPage(@RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize){
        PageInfo<Admin> pageInfo = adminService.selectPage(pageNum,pageSize);
        return Result.success(pageInfo);
    }

}
